﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QuanLyPhongKham
{
    public partial class CrudOperation : XtraUserControl
    {

        /// <summary>
        /// Occurs when [button click].
        /// </summary>
        public event EventHandler<DBOperateEventArgs> ButtonClick;
        public CrudOperation()
        {
            InitializeComponent();}

        private void butMoi_Click(object sender, EventArgs e)
        {
            this.butLuu.Enabled = true;
            this.butBoqua.Enabled = true;
            this.butMoi.Enabled = true;
            this.butXoa.Enabled = false;
            this.butSua.Enabled = false;
            OnButtonClick(sender, new DBOperateEventArgs(ButtonType.New));

        }

        private void butSua_Click(object sender, EventArgs e)
        {
            this.butSua.Enabled = true;
            this.butLuu.Enabled = true;
            this.butBoqua.Enabled = true;
            this.butMoi.Enabled = false;
            this.butXoa.Enabled = false;
            OnButtonClick(sender, new DBOperateEventArgs(ButtonType.Edit));
        }

        private void butHuy_Click(object sender, EventArgs e)
        {
            
            OnButtonClick(sender, new DBOperateEventArgs(ButtonType.Delete));
        }

        private void butLuu_Click(object sender, EventArgs e)
        {
            OnButtonClick(sender, new DBOperateEventArgs(ButtonType.Save));
            this.butXoa.Enabled = true;
            this.butLuu.Enabled = false;
            this.butBoqua.Enabled = false;
            this.butMoi.Enabled = true;
            this.butSua.Enabled = true;
        }

        private void butBoqua_Click(object sender, EventArgs e)
        {
            OnButtonClick(sender, new DBOperateEventArgs(ButtonType.Ignore));
            this.butXoa.Enabled = true;
            this.butLuu.Enabled = false;
            this.butBoqua.Enabled = false;
            this.butMoi.Enabled = true;
            this.butSua.Enabled = true;
        }

        protected virtual void OnButtonClick(object sender, DBOperateEventArgs e) {
            if (this.ButtonClick != null) {
                this.ButtonClick(sender, e);
            }
        }

    }

    public class DBOperateEventArgs : EventArgs {
        public ButtonType ButtonKind;
        public DBOperateEventArgs()
        {

        }
        public DBOperateEventArgs(ButtonType kind)
        {
            this.ButtonKind = kind;
        }
    }

    public enum ButtonType { 
        New,
        Edit,
        Delete,
        Save,
        Ignore
    }
}
